package com.yingxue.lesson.controller;

import com.yingxue.lesson.entity.SysRole;
import com.yingxue.lesson.exception.DataResult;
import com.yingxue.lesson.service.SysRoleService;
import com.yingxue.lesson.vo.req.AddRoleReqVO;
import com.yingxue.lesson.vo.req.RolePageReqVO;
import com.yingxue.lesson.vo.resp.PageVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * (SysRole)表控制层
 *
 * @author makejava
 * @since 2022-04-05 21:40:53
 */
@RestController
@RequestMapping("/api")
public class SysRoleController {
    /**
     * 服务对象
     */
    @Resource
    private SysRoleService sysRoleService;

    @PostMapping("/roles")
    @ApiOperation(value = "分页获取角色数据接口")
    public DataResult<PageVO<SysRole>> pageInfo(@RequestBody RolePageReqVO vo){
        DataResult result =DataResult.success();
        PageVO<SysRole> sysRolePageVO = sysRoleService.pageInfo(vo);
        result.setData(sysRolePageVO);
        return result;
    }


    @PostMapping("/role")
    @ApiOperation(value = "新增角色接口")
    public DataResult<SysRole> addRole(@RequestBody @Valid AddRoleReqVO vo){
        DataResult result =DataResult.success();
        SysRole sysRole = sysRoleService.addRole(vo);
        result.setData(sysRole);
        return result;
    }



}

